package worklog.dto;

import com.google.gson.Gson;

public class ResponseDTO {
	public static enum ResultType {SUCCESS, ERROR, AUTH};
	String msg;
	String result;
	ResultType resType;
	
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public String getResult(){
		return this.result;
	}	
	
	public void setResult(ResultType resType){
		switch(resType){
			case ERROR : this.result = "error"; break;
			case AUTH : this.result = "auth"; break;
			default : this.result = "success"; break;
		}
	}
	
	public String showError(){ return this.showError("Incorrect parameters"); }	
	public String showError(String msg){
		this.setMsg(msg);
		this.setResult(ResultType.ERROR);
		return this.toString(); 
	}
	
	public String showSuccess(){ 
		return this.showSuccess(""); 
	}	
	public String showSuccess(String msg){
		this.setMsg(msg);
		this.setResult(ResultType.SUCCESS);
		return this.toString(); 
	}
	public String showAuthError(){ 
		this.setMsg("Authentication error");
		this.setResult(ResultType.AUTH);
		return this.toString(); 
	}
	
	
	@Override
	public String toString(){		
		return new Gson().toJson(this);
	}
	
}
